<!--
 * @Date: 2022-12-06 08:57:16
 * @LastEditTime: 2022-12-19 14:57:56
 * @Description: content
-->
<template>
	<view class="page-wrap">
		<uni-nav-bar color="#333" leftIcon="left" backgroundColor="#fff" :border="false" :statusBar="true"
			:fixed="true">
			<view slot="left" class="nav-left">
				<uni-icons @click="$common.back()" :style="{
            fontWeight: 'normal'
          }" type="left" color="#333" size="20" />

				<view @click="toHome" class="icon">
					<cimage src="/static/icon/home.png" mode="scaleToFill" />
				</view>
			</view>
		</uni-nav-bar>

		<swiper autoplay circular>
			<swiper-item v-for="(item, i) in pageData.thumb" :key="i">
				<cimage :src="item" mode="scaleToFill" />
			</swiper-item>
		</swiper>

		<u-gap height="20"></u-gap>

		<view class="goods-info">
			<view class="goods-info-hd">
				<view class="price">
					¥

					<text>{{ pageData.price }}</text>
				</view>

				<!-- <view class="pre-price">
          市场价:

          <text>{{ pageData.old_price }}</text>
        </view> -->

				<!-- <view class="buy-num">{{ pageData.sales }}人付款</view>

        <view class="want">{{ pageData.collect_num || 0 }}人想要</view> -->
			</view>

			<view class="goods-info-bd">
				{{ pageData.title }}
			</view>
		</view>

		<u-gap height="30"></u-gap>

		<view class="zheng-pin">
			<cimage src="/static/img/zheng_pin.png" mode="scaleToFill" />
		</view>

		<view class="goods-tag">
			<view class="goods-tag-item">
				<view class="icon">
					<cimage src="/static/icon/check2_act.png" mode="scaleToFill" />
				</view>

				假一罚三
			</view>

			<view class="goods-tag-item">
				<view class="icon">
					<cimage src="/static/icon/check2_act.png" mode="scaleToFill" />
				</view>

				正品保障
			</view>

			<view class="goods-tag-item">
				<view class="icon">
					<cimage src="/static/icon/check2_act.png" mode="scaleToFill" />
				</view>

				全新正品
			</view>

			<view class="goods-tag-item">
				<view class="icon">
					<cimage src="/static/icon/check2_act.png" mode="scaleToFill" />
				</view>

				超时赔付
			</view>
		</view>

		<!-- <u-gap height="20"></u-gap> -->

		<!-- <view class="choose-info">
      <view class="row">
        <view class="title">已选规格</view>

        <view class="right">{{ specCur === '' ? '选择规格' : '已选择' }}</view>
      </view>

      <view class="row">
        <view class="title">收货地址</view>

        <view class="right">
          <template v-if="addressData">
            {{ addressData.address }}
          </template>

          <template v-else>
            <view class="icon">
              <cimage src="/static/icon/address.png" mode="scaleToFill" />
            </view>

            选择收货地址
          </template>
        </view>
      </view>

      <view class="row">
        <view class="title">商品运费</view>

        <view class="right">
          {{
            specCur === ''
              ? '以订单页面实际支付金额为准'
              : '以订单页面实际支付金额为准'
          }}
        </view>
      </view>
    </view> -->

		<u-gap height="20"></u-gap>

		<view v-html="pageData.editor" class="detail"></view>

		<view class="bt-fixed">
			<!-- <view @click="toggleCollect" class="sm-btn">
        <view class="icon">
          <cimage
            v-if="pageData.is_collect == 1"
            src="/static/icon/fav_act.png"
            mode="scaleToFill"
          />

          <cimage v-else src="/static/icon/fav.png" mode="scaleToFill" />
        </view>

        <view class="title">想要</view>
      </view> -->

			<view class="sm-btn relative">
				<button class="hide" open-type="share"></button>

				<view class="icon">
					<cimage src="/static/icon/share1.png" mode="scaleToFill" />
				</view>

				<view class="title">分享</view>
			</view>

			<view class="sm-btn relative">
				<button class="hide" open-type="contact"></button>

				<view class="icon">
					<cimage src="/static/icon/ke_fu.png" mode="scaleToFill" />
				</view>

				<view class="title">客服</view>
			</view>

			<view @click="openBuyPop" class="lg-btn">
				立即更换
			</view>

			<!-- <view v-else class="lg-btn dis">未选订单</view> -->
		</view>

		<uni-popup ref="buyPop" type="bottom">
			<view v-if="pageData" class="buy-pop">
				<view class="buy-pop-hd">
					<view @click="closeBuyPop" class="close icon">
						<cimage src="/static/icon/close2.png" mode="scaleToFill" />
					</view>
				</view>

				<view class="buy-pop-bd">
					<view class="info">
						<view class="pic">
							<cimage :src="pageData.thumb[0]" mode="scaleToFill" />
						</view>

						<view class="info-content">
							<view class="title hang2">
								{{ pageData.title }}
							</view>

							<view class="price-num">
								<view class="price">
									¥

									<text>
										{{ pageData.price }}

										<!-- <text>¥233333</text> -->
									</text>
								</view>

								<view class="has">
									<!-- 库存:233 -->
								</view>
							</view>
						</view>
					</view>

					<view @click="toOrder" class="buy-btn">更换</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				optionsData: '',
				specCur: '',
				addressData: '',
				buyNum: 1,
				pageData: ''
			}
		},

		onShareAppMessage() {
			return {
				title: `快来置换${this.pageData.title}!`,
				imageUrl: this.pageData.thumb[0],
				path: `/package/index/exchange-detail?id=${this.pageData.id}`
			}
		},

		onLoad(options) {
			this.optionsData = options
			this.getData()
		},

		onReady() {
			// this.openBuyPop()
		},

		methods: {
			/**
			 * @description: 获取数据
			 * @return {*}
			 */
			getData() {
				this.req({
					url: '/v1/shop/change/info',
					data: {
						id: this.optionsData.change_id
					},
					Loading: true,
					success: res => {
						if (res.code == 200) {
							if (res.data.editor) {
								res.data.editor = res.data.editor.replace(
									/\<img/gi,
									'<img style="width: 100%;vertical-align: middle;"'
								)
							}
							this.pageData = res.data
						}
					}
				})
			},

			/**
			 * @description: 前往订单页
			 * @return {*}
			 */
			toOrder() {
				this.$common.to({
					url: '/package/index/exchange-order',
					query: this.optionsData
				})
			},

			/**
			 * @description: 验证购买数量
			 * @return {*}
			 */
			checkBuyNum() {
				if (this.buyNum <= 1) {
					this.buyNum = 1
				}

				if (this.buyNum >= 10) {
					this.buyNum = 10
				}
			},

			/**
			 * @description: 兑换数量减
			 * @return {*}
			 */
			jian() {
				if (this.buyNum <= 1) {
					this.buyNum = 1
					return
				}

				this.buyNum -= 1
			},

			/**
			 * @description: 兑换数量加
			 * @return {*}
			 */
			jia() {
				if (this.buyNum >= 10) {
					this.buyNum = 10
					return
				}

				this.buyNum += 1
			},

			/**
			 * @description: 关闭购买弹窗
			 * @return {*}
			 */
			closeBuyPop() {
				this.$refs.buyPop.close()
			},

			/**
			 * @description: 打开购买弹窗
			 * @return {*}
			 */
			openBuyPop() {
				this.$refs.buyPop.open()
			},

			/**
			 * @description: 前往首页
			 * @return {*}
			 */
			toHome() {
				this.$common.to({
					type: 3,
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	.page-wrap {
		padding-bottom: 128rpx;

		.nav-left {
			display: flex;
			align-items: center;

			.icon {
				width: 50rpx;
				height: 50rpx;
				margin-left: 30rpx;
			}
		}

		swiper {
			width: 100%;
			height: 750rpx;
		}

		.goods-info {
			padding: 30rpx;
			background: #fff;

			&-hd {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.price {
					font-size: 24rpx;
					font-family: SourceHanSansCN;
					font-weight: 800;
					color: #333333;

					text {
						font-size: 38rpx;
					}
				}

				.pre-price {
					font-size: 24rpx;
					font-family: PingFang SC;
					// font-weight: bold;
					color: #999999;

					text {
						text-decoration: line-through;
					}
				}

				.buy-num {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}

				.want {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
				}
			}

			&-bd {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #222222;
				line-height: 43rpx;
				margin-top: 20rpx;
			}
		}

		.zheng-pin {
			width: 100%;
			height: 114rpx;
		}

		.goods-tag {
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			background: #fff;

			&-item {
				display: flex;
				align-items: center;

				.icon {
					width: 30rpx;
					height: 30rpx;
					margin-right: 4rpx;
				}

				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #222222;
				line-height: 30rpx;
			}
		}

		.choose-info {
			background: #fff;
			padding: 30rpx;

			.row {
				display: flex;
				align-items: center;

				font-size: 24rpx;
				font-family: PingFang SC;
				// font-weight: bold;
				color: #999999;

				.title {
					width: 150rpx;
				}

				.right {
					display: flex;
					align-items: center;

					.icon {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}

			.row+.row {
				margin-top: 30rpx;
			}
		}

		.detail {
			font-size: 26rpx;
			font-family: PingFang SC;
			color: #222222;
			line-height: 43rpx;
			background: #fff;
		}

		.bt-fixed {
			position: fixed;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 128rpx;
			background: #fff;
			box-shadow: 0rpx -3rpx 9rpx 0rpx rgba(115, 115, 115, 0.3);
			z-index: 10;
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
			padding: 0 30rpx;

			.sm-btn {
				display: flex;
				flex-flow: column nowrap;
				align-items: center;

				.icon {
					width: 50rpx;
					height: 50rpx;
				}

				.title {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					// margin-top: 10rpx;
				}
			}

			.lg-btn {
				width: 435rpx;
				height: 88rpx;
				background: #333333;
				border-radius: 10rpx;
				line-height: 88rpx;
				text-align: center;

				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;

				&.dis {
					background: #999999;
				}
			}
		}

		.buy-pop {
			background: #fff;

			&-hd {
				display: flex;
				justify-content: flex-end;
				padding: 20rpx 20rpx 0;

				.icon {
					width: 50rpx;
					height: 50rpx;
				}
			}

			&-bd {
				padding: 30rpx;

				.info {
					display: flex;

					.pic {
						width: 140rpx;
						height: 140rpx;
						border-radius: 10rpx;
						overflow: hidden;
					}

					&-content {
						width: calc(100% - 140rpx);
						box-sizing: border-box;
						padding-left: 30rpx;
						display: flex;
						flex-flow: column nowrap;
						justify-content: space-between;

						.title {
							font-size: 26rpx;
							font-family: PingFang SC;
							color: #222222;
							font-weight: bold;
						}

						.price-num {
							display: flex;
							align-items: center;
							justify-content: space-between;

							.price {
								font-size: 24rpx;
								font-family: Source Han Sans CN;
								font-weight: 800;
								color: #333333;

								text {
									font-size: 38rpx;

									text {
										padding-left: 10rpx;
										font-size: 24rpx;
										font-family: PingFang SC;
										font-weight: bold;
										text-decoration: line-through;
										color: #999999;
									}
								}
							}

							.has {
								font-size: 26rpx;
								font-family: PingFang SC;
								font-weight: bold;
								color: #999999;
							}
						}
					}
				}

				.row-title {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #222222;
					margin-top: 30rpx;

					&.no-margin {
						margin: 0;
					}

					&.bold {
						font-weight: bold;
					}
				}

				.line {
					width: 100%;
					height: 1rpx;
					background: #eeeeee;
					margin-top: 30rpx;
				}

				.spec-wrap {
					max-height: 40vh;
				}

				.spec {
					&-list {
						display: flex;
						flex-flow: row wrap;
						padding: 1rpx 0 0;

						&-item {
							margin-top: 30rpx;
							margin-right: 30rpx;
							padding: 0 30rpx;
							height: 66rpx;
							background: #ebebeb;
							line-height: 66rpx;

							font-size: 26rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #222222;

							&.act {
								background: #000;
								color: #fff;
							}
						}
					}
				}

				.row {
					margin-top: 30rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.num-box {
						display: flex;
						align-items: center;

						.icon {
							width: 50rpx;
							height: 50rpx;
						}

						input {
							height: 36rpx;
							width: 80rpx;
							margin: 0 10rpx;
							background: #ebeaef;

							font-size: 28rpx;
							font-family: PingFang SC;
							// font-weight: bold;
							color: #333333;
							text-align: center;
						}
					}
				}

				.buy-btn {
					width: 100%;
					height: 88rpx;
					line-height: 88rpx;
					text-align: center;
					background: #333333;
					margin-top: 60rpx;
					border-radius: 999rpx;

					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #ffffff;
				}
			}
		}
	}
</style>